[ Home ] [ Authors ] [ Index ] [ Abbreviations ] [ Bindings ]

DialogWindow Class

The common base class for all dialogs with the user is the DialogWindow class. You can use this class to create customized interactions. For example,

::tycho::DialogWindow .m -text {A dialog with a single customized pushbutton}
.m addButton pushme -text {Push Me} -command {post thanks}
wm deiconify .m
We have created a widget named ".m" and inserted into it a button named "pushme". The addButton method is defined in the class DialogWindow. The button is bound to the command "post thanks". This class is derived from TopLevel, so you can center it on the screen, freeze the window size, etc.

You can mark the button as a default button with the following command:

.m default pushme
This changes the appearance of the button, and has the side effect of binding the Return key so that invokes the button. Try placing the mouse in the window and hitting Return.

You can also directly invoke a button from a script using the invoke method:

.m invoke pushme
You can insert a bitmap into the message window:
.m configure -bitmap questhead
The value, "questhead", is the name of a built-in bitmap. Other particularly useful ones are "error", "info", "question", "hourglass", and "warning". As with any option, we could have specified the -bitmap option in the original command creating the widget.

You can also insert an image created with the "image create" command, using the Tk photo widget.

image create photo ptgif -file $TYCHO/kernel/img/ptolemyWelcome.gif
.m configure -image ptgif
You can remove the DialogWindow object with the following command:
delete object .m

There are two procedures defined in the DialogWindow class to support creation of modal and non-modal dialog boxes. Each of them takes the name of a class (which must be derived from DialogWindow), an instance name, and optional set of arguments, and creates an instance of the class. The new procedure creates a non-modal dialog:

::tycho::DialogWindow::new Message .y -text {This message is automatically mapped}
The only advantage of using this feature is that message automatically appears in the center of the screen, without having to issue a second command. This is not a big advantage.

If we wanted to create a modal dialog, we could use the newModal procedure:

::tycho::DialogWindow::newModal Message .y \
    -text {This message must be dismissed before you can continue}
The newModal procedure is a convenience that replaces several lines of Tcl code that would be required to make the dialog box modal. Moreover, the newModal procedure returns the value returned by the script called when the button is pushed. This allows us to create modal dialogs that return a value.


Copyright © 1996, The Regents of the University of California. All rights reserved.
Last updated: 96/04/09, comments to: eal@eecs.berkeley.edu